package com.rgs.gateway.web.service.impl;


import cn.hutool.core.util.StrUtil;
import com.rgs.gateway.authentication.feignclient.client.AuthFeignClient;
import com.rgs.gateway.common.pojo.Result;
import com.rgs.gateway.web.service.IPermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class PermissionServiceImpl implements IPermissionService {


    @Autowired
    private AuthFeignClient authFeignClient;
    @Override
    public boolean permission(String authentication, String url, String method) {
        //如果请求信息未携带账户信息（公钥），直接返回异常信息
        if (StrUtil.isBlank(authentication) ) {
            log.error("user token is null");
            return Boolean.FALSE;
        }
        Result authResult = authFeignClient.permission(authentication, url, method);

        return authResult.isSuccess() && (boolean) authResult.getData();
    }
}
